﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.Reputation.Tests.FrontEndCommon
{
    public class TAEFHelper
    {
        public TAEFHelper()
        { }

        /// <summary>
        /// This function is to read data from the DataDriven XML and return the string. It also handles the case in which you dont have the certain Parameter name in your row.
        /// This could happen when you dont need to specify all the inputs for a test case, so instead of having empty Parameter rows, you can just omit the particular Parameter and this function will handle the exception that is thrown.
        /// </summary>
        /// <param name="testContext"></param>
        /// <param name="parameterName"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static bool GetData(TestContext testContext, string parameterName, out string data)
        {
            bool result = true;
            data = string.Empty;
            
            try
            {
                data = testContext.DataRow[parameterName].ToString();
            }
            catch
            {   // Catching all exceptions here. This can be improved to catch the particular exception we are expecting.
                result = false;
            }

            return result;
        }

        /// <summary>
        /// TRIAL FUNCTION. This will Supress any Logging done by TAEF. 
        /// </summary>
        public static void SurpressLogging()
        {
            Process proc = Process.GetCurrentProcess();
            Console.WriteLine(proc.ProcessName + "_CMD");

            Environment.SetEnvironmentVariable("TE_CMD", "/disableConsoleLogging"); 
        }

    }
}
